package com.spring.properties_demo;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.PropertySources;

public class App {
	public static void main(String[] args) {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
		PropertySourcesPlaceholderConfigurer properties = (PropertySourcesPlaceholderConfigurer) context.getBean("properties");
		PropertySources appliedPropertySources = properties.getAppliedPropertySources();
		PropertySource<?> localProperties = appliedPropertySources.get("localProperties");
		String property = (String) localProperties.getProperty("datasource.url");
		System.out.println(property);
		PropertySource<?> environmentProperties = appliedPropertySources.get("environmentProperties");

		appliedPropertySources.stream().map(PropertySource::getName).forEach(System.out::println);
	}
}
